from mysql_config import db
from datetime import datetime


# 用户表
class User(db.Model):
    __tablename__ = 'user'

    uid = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), nullable=False, unique=True)
    pwd = db.Column(db.String(20), nullable=False)
    name = db.Column(db.String(50), nullable=False)
    tel = db.Column(db.String(11), nullable=False, unique=True)
    mail = db.Column(db.String(50), nullable=True, unique=True)
    actor = db.Column(db.Integer, default=0)

    addr_pr = db.Column(db.String(50), nullable=True)
    addr_city = db.Column(db.String(50), nullable=True)
    addr_town = db.Column(db.String(50), nullable=True)
    addr_district = db.Column(db.String(50), nullable=True)
    addr_street = db.Column(db.String(50), nullable=True)


# 订单表
class UserOrder(db.Model):
    __tablename__ = 'user_order'

    order_id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    s_uid = db.Column(db.Integer, nullable=False)
    s_name = db.Column(db.String(50), nullable=False)
    s_tel = db.Column(db.String(11), nullable=False)
    s_addr_pr = db.Column(db.String(50), nullable=True)
    s_addr_city = db.Column(db.String(50), nullable=True)
    s_addr_town = db.Column(db.String(50), nullable=True)
    s_addr_district = db.Column(db.String(50), nullable=True)
    s_addr_street = db.Column(db.String(50), nullable=True)

    r_uid = db.Column(db.Integer, nullable=True)
    r_name = db.Column(db.String(50), nullable=False)
    r_tel = db.Column(db.String(11), nullable=False)
    r_addr_pr = db.Column(db.String(50), nullable=True)
    r_addr_city = db.Column(db.String(50), nullable=True)
    r_addr_town = db.Column(db.String(50), nullable=True)
    r_addr_district = db.Column(db.String(50), nullable=True)
    r_addr_street = db.Column(db.String(50), nullable=True)

    item_num = db.Column(db.Integer, nullable=False)
    item_type = db.Column(db.String(50), nullable=False)
    item_weight = db.Column(db.Integer, nullable=True)
    remark = db.Column(db.String(200), nullable=True)
    state = db.Column(db.Integer, nullable=False)

    begin_lnglat = db.Column(db.String(24), nullable=False)
    end_lnglat = db.Column(db.String(24), nullable=False)

    order_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)

    car_id = db.Column(db.Integer, nullable=True)


# 物品状态表
class ItemState(db.Model):
    __tablename__ = 'item_state'

    order_id = db.Column(db.Integer, primary_key=True)

    i_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
    i_temp = db.Column(db.Float, nullable=False)
    i_hum = db.Column(db.Float, nullable=False)


# 地点信息表
class Location(db.Model):
    __tablename__ = 'location'

    order_id = db.Column(db.Integer, primary_key=True)

    loc = db.Column(db.String(100), nullable=True)
    point = db.Column(db.String(24), nullable=False)


# 配送车信息
class Car(db.Model):
    __tablename__ = 'car'

    car_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    car_num = db.Column(db.Integer, nullable=False, unique=True)
    car_state = db.Column(db.Integer, default=0)
    control_data = db.Column(db.String(6))

